env = ENV['RAILS_ENV'] || 'development' 
database = "yellowpage_#{env}" 
user = "ypuser_#{env[0..0]}"

require 'rubygems'
gem 'ActiveRecord-JDBC'
gem 'activerecord'
require 'jdbc_adapter'
require 'active_record'

task :db_connect do
ActiveRecord::Base.establish_connection(
:adapter => 'jdbc',
:driver => 'com.mysql.jdbc.Driver',
:url => 'jdbc:mysql://localhost/mysql',
:username => 'root',
:password => 'ror'
) end

task :db_setup => [ :db_connect ] do 
ActiveRecord::Schema.define do
create_database database 
execute "create user #{user}@localhost identified by 'ror'"
execute "grant all privileges on #{database}.* to '#{user}'@'localhost'"
 end

end
task :db_clean => [ :db_connect ] do

ActiveRecord::Schema.define do

execute "drop user '#{user}'@'localhost'"

drop_database database

end
end


